﻿@page
@model KentNoteBook.WebApp.Pages.LoginModel
@{
	ViewData["Title"] = "Login";
}

<div class="container justify-content-center">
	<div class="card mt-5 mx-auto login-card">
		<div class="card-header">
			Login
		</div>
		<div class="card-body pb-1">
			<form id="form_login" method="post" ajax-form="true" asp-page-handler="Submit">
				<div class="form-group row">
					<label class="col-sm-12 col-form-label" for="UserName">User Name </label>
					<div class="col-sm-12">
						@Html.TextBoxFor(x => x.Data.UserName, new { @class = "form-control", placeholder = "User Name" })
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-12 col-form-label" for="Password">Password</label>
					<div class="col-sm-12">
						@Html.PasswordFor(x => x.Data.Password, new { @class = "form-control", placeholder = "Password" })
					</div>
				</div>

				<div class="form-group row">
					<div class="col-sm-12">
						<button id="btnLogin" type="submit" class="btn btn-primary btn-block" ajax-button="true" data-alert-panel="#form_login_alert_panel" asp-page-handler="Submit">Submit</button>
					</div>
				</div>
				@Html.ValidationSummary(false, null, new { @class = "alert alert-danger" })
				<div id="form_login_alert_panel"></div>
			</form>
		</div>
	</div>
</div>

@section Scripts{

	<script type="text/javascript">

	$("#pageBody").addClass("bg-dark");
	$("#pageBody nav").hide();

	$(function () {

		$("#btnLogin").data("ajaxCallback", function (data) {
			if (data && data.Code) {
				localStorage.setItem("access_token", data.Data.access_token);
				localStorage.setItem("expires_at", data.Data.expires_at);

				//$.renderPartial($("app-root"), "/AppRoot?_=@DateTime.Now.Millisecond");
				location.href = "/";
			}
		});
	});
	</script>

}

